package dataflowScheme.diagram.sheet.customProperties;

import org.eclipse.core.resources.IFile;
import org.eclipse.emf.common.ui.celleditor.ExtendedDialogCellEditor;
import org.eclipse.emf.common.ui.dialogs.WorkspaceResourceDialog;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EDataType;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
import org.eclipse.emf.edit.ui.provider.PropertyDescriptor;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;


public class CustomizedPropertyDescriptor extends PropertyDescriptor {

	public CustomizedPropertyDescriptor(Object object,
			IItemPropertyDescriptor itemPropertyDescriptor) {
		super(object, itemPropertyDescriptor);
		// TODO Auto-generated constructor stub
	}

	public CellEditor createPropertyEditor(Composite composite) {
		   CellEditor result = super.createPropertyEditor(composite);
		    
		   if(result == null) return result;
		   EClassifier eType =         ((EStructuralFeature)itemPropertyDescriptor.getFeature(object)).getEType();
		   if (eType instanceof EDataType) {
		      EDataType eDataType = (EDataType) eType;
		      
		      if(eDataType.getName().equalsIgnoreCase("SourceType")){
		         result = new ExtendedDialogCellEditor(composite, getEditLabelProvider()){
		             protected Object openDialogBox(Control cellEditorWindow) {
		            	 
		            	IFile[] files = WorkspaceResourceDialog.openFileSelection(cellEditorWindow.getShell(), null, null, false, null, null);
		            	return files[0].getFullPath().toString();
		            }
		         };
		      }
		   }
		   return result;
		}
}
